<?php if (!defined('THINK_PATH')) exit();?> 
 
<html>
    <head>
        <meta charset="utf-8"> 
        <title>美业红</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.min.js'></script>    
        <link rel="stylesheet" href="/public/css/admin.css">
    </head>
    <body>
 <div class="container" style="background-color: white">  
<div class='content'>
<form action='/admin/item/submit' method='post'  id='form'>
    
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品名称:</label>
            <input type="text" class="row _minput" name='name' placeholder="" value="<?php echo $item['name'];?>"/>
        </div>
    </div>
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品小标题:</label>
            <input type="text" class="row _minput" name='title' placeholder="" value="<?php echo $item['title'];?>"/>
        </div>
    </div>
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品种类:</label>
            <select id="type" name="type" class="_select valid">
                <option value='0' <?php if($item['type'] == 0){echo 'selected="selected"';}?> >护理</option>
                <option value='1' <?php if($item['type'] == 1){echo 'selected="selected"';}?> >彩妆</option>
            </select>
        </div>
    </div>
  
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品价格:</label>
            <input type="text"  name='price' placeholder="" value="<?php echo ($item['price']/100);?>" style='width:5%' >&nbsp;元
        </div>
    </div>
<!-- 属性start -->    
    <div>
        <div class="form-group row">
            <label for="exampleInputName2" class="_label" >商品规格:</label>
            <label style='width:15%;' >品牌：<input name="brand" type="text" value="" style='width:40%' /></label>
            <label >重量：<input name="weight" type="text" value="" style='width:20%' /></label>
            <input type='button' style='margin-left:-10%;' value='添加' id='_add'  >
            <div> <label for="exampleInputName2" class="_label" ></label> </div>
        </div>
    </div>
<!-- 属性end -->    
        <div   >
        <div class='form-group row'  >
                <label style='float:left' for="exampleInputName2" class="_label">商品图:</label>
                 <div style='padding-bottom:2rem'> 
                    <input type='button' value='添加' id='add'  >
                    <span class="_prompt">宣传用图片建议长宽比例1:1；2M以内，支持“jpg,jpeg,png”</span>
                </div>
                <label style='float:left' for="exampleInputName2" class="_label"></label>
                <span id='ad' style='float:left'>
                <?php if($item['id']>0){ $h = count($item['images']); ?>
                <?php foreach($item['images'] as $k=>$v){ ?>
                <span id='asd' style='float:left' >
                    
                <img src="<?php echo "http://".IMAGE_DOMAIN.$item['images'][$k]['image']; ?>" style="width:20rem;height: 20rem;border:1px;border-color: black" id="s<?php echo $k;?>_img"  alt='商品图1'/>
                <?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/admin/item/create')){ ?>
                <a href='javascript:;'; onclick='error_(this)'; ><img src='/public/images/error1.png' width='20px' style='margin-top:-20rem;margin-left:-1rem;' ></a>
                <?php } ?>
                <input type='hidden' name='image[]' value="<?php echo $item['images'][$k]['image'];?>" id='s<?php echo $k;?>'>
                <div >
                    <iframe id='imgs' src="http://<?php  echo IMAGE_DOMAIN;?>/index.php?id=s<?php echo $k;?>&type=2" frameborder="no" border="0" scrolling='no' style="width:25rem;height: 4rem;padding-top: 1rem" ></iframe>
                </div>
                </span>
                <?php } ?>
                <?php }else{?>
                <span id='asd' style='float:left' >
                <img src="<?php echo "http://".IMAGE_DOMAIN.'/upload/product.png'; ?>" style="width:20rem;height:20rem;border:1px;border-color: black" id="s0_img"  alt='商品图'/>
                <input type='hidden' name='image[]' value="<?php echo '/upload/product.png'; ?>" id='s0'>
                <div >
                    <iframe id='imgs' src="http://<?php  echo IMAGE_DOMAIN;?>/index.php?id=s0&type=2" frameborder="no" border="0" scrolling='no' style="width:25rem;height: 4rem;padding-top: 1rem" ></iframe>
                </div>
                <?php }?> 
                
                </span>
                </span>
               
        </div>
        </div>
    <!-- 商品详情图 -->
    <div>
        
        <div class='form-group row'  >
                <label style='float:left' for="exampleInputName2" class="_label">商品详情图:</label>
                <span id='ad' style='float:left'>
                <?php if($item['id']>0){ ?>
                <span id='asd' style='float:left' >
                    
                <img src="<?php echo "http://".IMAGE_DOMAIN.$item['intro'][0]; ?>" style="width:20rem;height: 20rem;border:1px;border-color: black" id="s<?php echo $k;?>_img"  alt='商品详情图'/>
                <input type='hidden' name='intro[]' value="<?php echo $item['intro'][0];?>" id='s<?php echo $k;?>'>
                <div >
                    <iframe id='images' src="http://<?php  echo IMAGE_DOMAIN;?>/index.php?id=s<?php echo $k;?>&type=3" frameborder="no" border="0" scrolling='no' style="width:25rem;height: 4rem;padding-top: 1rem" ></iframe><span class="_prompt">宣传用图片建议长图；5M以内，支持“jpg,jpeg,png”</span>
                </div>
                </span>
                <?php }else{?>
                <span id='asd' style='float:left' >
                <img src="<?php echo "http://".IMAGE_DOMAIN.'/upload/product.png'; ?>" style="width:20rem;height:20rem;border:1px;border-color: black" id="s0_image"  alt='商品详情图'/>
                <input type='hidden' name='intro[]' value="<?php echo '/upload/product.png'; ?>" id='s0'>
                <div >
                    <iframe id='images' src="http://<?php  echo IMAGE_DOMAIN;?>/index.php?id=s0&type=3" frameborder="no" border="0" scrolling='no' style="width:25rem;height: 4rem;padding-top: 1rem" ></iframe><span class="_prompt">宣传用图片建议长图；5M以内，支持“jpg,jpeg,png”</span>
                </div>
                <?php }?> 
                
                </span>
                </span>
        </div>
    </div>
 <!-- 商品详情图end -->

        <div class='form-group row'>
            <div><label for="exampleInputName2" class="_label">商品介绍:</label></div>
                <label for="exampleInputName2" class="_label"></label>
                <textarea name='intro[]' id="_intro" class="_textarea" style="width:40%"><?php echo $item['intro'][1]; ?></textarea>
        </div>
        <div class="form-group _submit_div row">
                <input name='create' id='create' class='_button' type="button" value="预览" onclick="_submit(2);"/>
                <input name='caogao' id='caogao' class='_button' type="submit" value="保存草稿" onsubmit="return _submit(1);"/>
        </div>
</form>

</div>
</div>
<script type="text/javascript">
    
$(document).ready(function () {

 var n = Number($('#ad').children().length)+Number(1);
$('#add').click(function(){
    if($('#ad').children().length==4){
        alert('最多添加4张图片！');
        return;
    }

    var html='';
    html += "<span style='float:left' id='as";
    html += n;
    html += "'; ><img src='<?php echo 'http://'.IMAGE_DOMAIN.'/upload/product.png'; ?>' style='width:20rem;height:20rem;border:1px;border-color: black' id='s";
    html += n;
    html +="_img'  alt='商品图'/><a href='javascript:;'; onclick='error(";
    html += n;
    html += ")'; ><img src='/public/images/error1.png' width='20px' style='margin-top:-11rem;' ></a>";
    html +="<input type='hidden' name='image[]' value='<?php echo '/upload/product.png'; ?>' id='s";
    html += n;
    html +="'><div ><iframe id='imgs' src='http://<?php  echo IMAGE_DOMAIN;?>/index.php?id=s";
    html += n;
    html +="&type=2' frameborder='no' border='0' scrolling='no' style='width:25rem;height: 4rem;padding-top: 1rem' ></iframe></div></span>";
    $('#ad').append(html);
    n = n+1;
});

//添加商品规格
$('#_add').click(function(){
    var htmls = '';
    htmls += "<label style='width:15%;' ><input name='attribute_key[]' type='text' value='' style='width:30%'/> ：<input name='attribute_value[]' type='text' value='' style='width:40%'/></label> ";
   $(this).next().append(htmls);

});

$("#form").validate({
        rules: {
            store_id: {
                required: true,
                min: 1,
            },
            name: {
                required: true,
            },
            title: {
                required: true,
            },
            type: {
                required: true,
            },
            is_meal_set: {
                required: true,
            },
            price: {
                required: true,
                number:true,
            }

        },
        messages: {
            store_id: {
                required: "请选择店铺",
                min: "请选择店铺",
            },
            name: {
                required: '请输入商品名称',
            },
            title: {
                required: '请输入商品副标题',
            },
            type: {
                required: '请商品种类',
            },
            is_meal_set: {
                required: '请商品类型',
            },
            price: {
                required: '请填写价格',
                number:'请填写数字',
            }

        
        }
    });

})
    
function error(n){
    $('#as'+n).remove();
}
function error_(obj){
    $(obj).parent().remove();

}

function _submit(type) {
    if (type == 1) {
        $('#create').remove();
    } else {
        $('#caogao').remove();
    }
    if($('input:hidden[name="image[]"]').val()== undefined){
        alert('请至少上传一张商品图！');
        return;
    }
    var content = $("#_intro").val();
    content = content.replace(/<br\/>/,"\n");
    content = content.replace(/<span style=\'color:red\'>/,"");
    content = content.replace(/<\/span>/,"");
    content = content.replace(/\n/g, "<br/>");
    content = content.replace(/[\d]{1,}/g, "<span style='color:red'>$&</span>");
    $("#_intro").val(content);
    $('#form').submit();
}
    

</script>
    </body>
</html>